package com.aluvfy.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class JDBCTest02 {
    public static void main(String[] args) throws Exception {
        //throws Exception 将异常直接抛出到JVM

        //getConnection()的重载方法---在DriverManger源码中getConnection中有多种传入参数
        //1. getConnection(String url, String user, String password) 这个是最基础的
        //2. getConnection(url)
//        Class.forName("com.mysql.cj.jdbc.Driver");
//        String url = "jdbc:mysql://localhost:3306/jdbc?user=root&password=root";
//        Connection conn = DriverManager.getConnection(url);
//        System.out.println(conn);

        // 3. getConnection(url, info-properties对象)
        Class.forName("com.mysql.cj.jdbc.Driver");
        //url
        String url = "jdbc:mysql://localhost:3306/jdbc";
        //info  map集合
        Properties info = new Properties();
        info.setProperty("user", "root");
        info.setProperty("password", "root");

        Connection conn = DriverManager.getConnection(url, info);
        System.out.println(conn);

    }
}
